/*
 * 20.10.2008 - Albert Weinert - erstellt.
 * 
 */
using System.Collections.Generic;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.Client;

namespace IssueExplorer.Providers.TeamFoundationServer.Managers
{
    public class WorkItemManager : IWorkItemManager
    {
        private readonly WorkItemStore store;
        private readonly Microsoft.TeamFoundation.Client.TeamFoundationServer server;

        public WorkItemManager()
        {
            server = TeamFoundationServerFactory.GetServer("http://jjktfs:8080");
            store = new WorkItemStore(server);
        }

        public IEnumerable<ProjectDTO> GetAllProjects()
        {
            IList<ProjectDTO> projects = new List<ProjectDTO>();
            foreach (Project project in store.Projects)
            {
                projects.Add(new ProjectDTO { Id = project.Id, Name = project.Name });
            }
            return projects;
        }

        public IEnumerable<SubProjectDTO> GetSubProjects(ProjectDTO project)
        {
            IList<SubProjectDTO> list = new List<SubProjectDTO>();
            Project p = store.Projects.GetById((int) project.Id);
            foreach (Node node in p.IterationRootNodes)
            {
                list.Add(new SubProjectDTO {Id = node.Id, Name = node.Uri.AbsoluteUri});
                foreach (Node childNode in node.ChildNodes)
                {

                list.Add(new SubProjectDTO {Id = childNode.Id, Name = childNode.Name});
                }
            }
            return list;
        }

        public IEnumerable<string> GetAssigned()
        {
            throw new System.NotImplementedException();
        }

        public IEnumerable<string> GetPossibleStatus()
        {
            throw new System.NotImplementedException();
        }
    }
}